function bpm = gettempo(nmat)
% function bpm = gettempo(nmat)
%
% Return the tempo (in BPM) of the nmat. Note that MIDI files can be encoded 
% using any arbitrary tempo.
%
% Input:
%	nmat [mat] - The notematrix
%
% Output:
%	bpm  [num] - Tempo (in beats per minute)
%

% Change History :
% Date		Time	Prog	Note
% 1.7.2003	18:52	TE	Created under MATLAB 5.3 (PC)
% Part of the MIDI Toolbox, Copyright 2004, University of Jyvaskyla, Finland
% See License.txt
% 
% Modified on 02/17/2010 by Graham Grindlay (grindlay@ee.columbia.edu) to
% fix bug that can occur if first event in nmat has an onset time of 0
%

% Copyright (C) 2010-2030 Graham Grindlay (grindlay@ee.columbia.edu)
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.

if isempty(nmat) 
    return
end

beat_dur = nmat(end,2);
time_dur = nmat(end,7); %
bpm = 60*(beat_dur/time_dur);
